<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <!--[if lt IE 9]>
            <script type="text/javascript" src="lib/html5shiv.js"></script>
            <script type="text/javascript" src="lib/respond.min.js"></script>
            <![endif]-->
    <link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
    <link rel="stylesheet" href="./../lib/layui/css/layui.css">
    <!--[if IE 6]>
            <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
            <script>DD_belatedPNG.fix('*');</script>
            <![endif]-->
    <style>
        .laytable-cell-1-0-3 {
            height: 100px;
            line-height: 100px;
        }
        .layui-table-view .layui-table th {
             height: 40px;
        }   
        .layui-table th div{
             height: 40px;
            line-height: 40px;
        }
        
    </style>
    <title>签到商品节点配置</title>
</head>

<body>
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 商品管理 <span
            class="c-gray en">&gt;</span>
        签到天数奖品配置 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);"
            title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="page-container">
        <table class="layui-hide" id="giftList" lay-filter="giftList"></table>
    </div>
    <script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="./../static/js/common.js"></script>
    <script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
    <script type="text/javascript" src="./../lib/layui/layui.js"></script>
    <script type="text/html" id="operation">
        <a  title="删除" lay-event="del" class=""><i class="Hui-iconfont" style = "font-size:20px;">&#xe6e2;</i></a>
    </script>
    <script type="text/html" id="toolbar">
        <div class="layui-btn-container">
            <div class="layui-btn-group">
                <button class="layui-btn layui-btn-sm" lay-event="t_add" onclick = "addCom()"><i class="layui-icon">&#xe654;</i></button>
            </div>
        </div>
    </script>
    <script>
        layui.use('table', function () {
            var table = layui.table;
            dataTable = table.render({
                elem: '#giftList',
                toolbar: '#toolbar',
                defaultToolbar: [],
                cellMinWidth: 80,
                url: admin_url + '/kvmSigninGiftSeting/signinGiftSetings',
                // id为重置表格，进行搜索
                id: 'reload',
                request: {
                    pageName: 'page',
                    limitName: 'size'
                },
                // 传输模式
                // contentType: 'application/json',
                paresData: function (res) {
                    return {
                        'data': res.data
                    }
                },
                response: {
                    statusCode: 200
                },
                // 传入数据
                where: {
                    tokenUserId: userId,
                    token: token
                },
                // 回调
                done: function (res, curr, count) {
                    console.log(res)
                },
                method: 'post',
                'page': 'true',
                cols: [[
                    { checkbox: true, align: 'center' },
                    { field: 'signInNo', title: '连续签到天数', align: 'center', },
                    {
                        field: 'giftProductId', title: '奖品名', align: 'center', templet: function (obj) {
                            var giftBag;
                            // 必须使用同步才能把值传出去
                            $.ajax({
                                type: "post",
                                xhrFields: { withCredentials: true },
                                url: admin_url + '/kvmGiftProduct/gift',
                                data: { tokenUserId: userId, token: token, id: obj.giftProductId },
                                async: false,
                                success: function (data) {
                                    console.log(data)
                                    if (data.code == 200 && data.data != null) {
                                        giftBag = '<span>' + data.data.name + '</span>'

                                    } else {
                                        giftBag = '<span></span>'
                                    }
                                    return giftBag
                                }
                            })
                            return giftBag
                        }
                    },

                    {
                        field: 'giftProductId', title: '奖品内容', align: 'center', style: 'height:100px;', templet: function (obj) {
                            var giftBag;
                            // 必须使用同步才能把值传出去
                            $.ajax({
                                type: "post",
                                xhrFields: { withCredentials: true },
                                url: admin_url + '/kvmGiftProduct/gift',
                                data: { tokenUserId: userId, token: token, id: obj.giftProductId },
                                async: false,
                                success: function (data) {
                                    console.log(data)
                                    if (data.code == 200 && data.data != null) {
                                        giftBag = '<img style ="height:100px;" src = "' + data.data.icon + '">'

                                    } else {
                                        giftBag = '<span></span>'
                                    }
                                    return giftBag
                                }
                            })
                            return giftBag
                        }
                    },
                    { toolbar: '#operation', title: '操作' }
                ]]
            })
            table.on('tool(giftList)', function (obj) {
                var data = obj.data;
                var id = data.id;
                if (obj.event == 'del') {
                    layer.confirm('是否删除?', { title: '删除' }, function (obj) {
                        $.ajax({
                            type: 'post',
                            xhrFields: { withCredentials: true },
                            url: admin_url + '/kvmSigninGiftSeting/delSigninGiftSeting',
                            data: { tokenUserId: userId, token: token, id: data.id },
                            success: function (data) {
                                if (data.code == 200) {
                                    layer.msg('删除成功', {
                                        time: 1000,
                                        end: function () {
                                            $(".layui-laypage-btn").click();
                                        }
                                    })
                                } else {
                                    layer.msg(data.msg, {
                                        time: 1500
                                    })
                                }
                            }
                        })
                    })
                }
            })
        })
        function addCom() {

            var index = layer.open({
                type: 2,
                title: '新增签到天数奖品',
                content: './add-gift-setting.html'
            })
            layer.full(index);
        }
    </script>

</body>

</html>